package com.wanlian.router.net.netty;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;

import com.google.gson.Gson;
import com.wanlian.router.net.netty2.msg.BaseMsg;
import com.wanlian.router.net.netty2.msg.Device.PPPoEGetReply;
import com.wanlian.router.net.netty2.msg.Device.model.PPPoE;
import com.wanlian.router.net.netty2.msg.MsgType;
import com.wanlian.router.net.netty2.msg.PeerMsg;




public class SocketService extends Service {

    private final static NettyClient client = new NettyClient();

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();

        new Thread(client).start();


    }

    public static void addMessage(String type, Object obj) {
        BaseMsg baseMsg = new BaseMsg();
        baseMsg.setType(type);
        baseMsg.setContent(new Gson().toJson(obj));
        addMessage(baseMsg);
    }

    public static void addMessage(String type, String contentJson) {
        BaseMsg baseMsg = new BaseMsg();
        baseMsg.setType(type);
        baseMsg.setContent(contentJson);
        addMessage(baseMsg);
    }

    public static void addMessage(BaseMsg msg) {
        PeerMsg peerMsg = new PeerMsg(msg);
        client.addMsg(peerMsg);
    }

}
